home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / Genie / Projects / Pedestal / Source / Sources / Panes / PedPaneIconAnimated.cc < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-24  |  2.4 KB  |  104 lines

  1. /*    ======================
  2.  *    PedPaneIconAnimated.cc
  3.  *    ======================
  4.  */
  5.  
  6. #include "PedestalDebugging.h"
  7.  
  8. #include <Icons.h>
  9.  
  10. #include "PedPaneIconAnimated.hh"
  11.  
  12. #include "PedView.hh"
  13. #include "Ped1AppProcess.hh"
  14. #include "PedApplication.hh"
  15.  
  16. static
  17. void
  18. AnimateIcon(void *inParam)
  19. {
  20.     if (inParam == NULL) return;
  21.     
  22.     PedPaneIconAnimated *icon = (PedPaneIconAnimated *)inParam;
  23.     icon->Animate();
  24. }
  25.  
  26. PedPaneIconAnimated::PedPaneIconAnimated(PedView &inSuperView)
  27. : PedPaneIcon(inSuperView), mAnimating(false)
  28. , mCountFrames(0), mCurrentFrame(0), mTicksPerFrame(4), mLastAdvance(0)
  29. , mAnimateChore(NULL)
  30. {
  31.     mCountFrames = 32;
  32.     mAnimateChore = new PedChoreGeneric(&AnimateIcon, (void *)this);
  33. }
  34.  
  35. PedPaneIconAnimated::~PedPaneIconAnimated()
  36. {
  37.     Ped1AppProcess::Me().MainModule().UnscheduleRepeatChore(mAnimateChore);
  38.     delete mAnimateChore;
  39. }
  40.  
  41. void
  42. PedPaneIconAnimated::Draw()
  43. {
  44.     Rect rect;
  45.     //::SetRect(&rect, 0, 0, 128, 128);
  46.     rect = mBounds;
  47.     Point offset;
  48.     mSuperView.GetWindowToLocalOffset(offset);
  49.     ::OffsetRect(&rect, offset.h, offset.v);
  50.     if (mCountFrames > 0) {
  51.         long range = 64;
  52.         long eccentricity = 2 * (mCurrentFrame - (mCountFrames / 2)) * (range / mCountFrames);
  53.         if (eccentricity < 0) {
  54.             eccentricity = -eccentricity;
  55.         }
  56.         ::InsetRect(&rect, eccentricity, range - eccentricity);
  57.     }
  58.     //::EraseRect(&rect);
  59.     //::PlotIconID(&mBounds, atAbsoluteCenter, ttNone, 128);
  60.     ::PlotIconID(&rect, atAbsoluteCenter, ttNone, 128);
  61. }
  62.  
  63. void
  64. PedPaneIconAnimated::Animate()
  65. {
  66.     mSuperView.Focus();
  67.     if (mAnimating) {
  68.         long ticks = ::TickCount();
  69.         if (ticks - mLastAdvance > mTicksPerFrame && mCountFrames > 0) {
  70.             mCurrentFrame = (mCurrentFrame + 1) % mCountFrames;
  71.             mLastAdvance = ticks;
  72.             ::EraseRect(&mBounds);
  73.             Draw();
  74.         }
  75.         //Ped1AppProcess::Me().MainModule().ScheduleRepeatChore(mAnimateChore);
  76.     }
  77. }
  78.  
  79. void
  80. PedPaneIconAnimated::DispatchClickEvent(EventRecord &inEvent)
  81. {
  82.     if (mAnimating = !mAnimating) {
  83.         Ped1AppProcess::Me().MainModule().ScheduleRepeatChore(mAnimateChore);
  84.     } else {
  85.         Ped1AppProcess::Me().MainModule().UnscheduleRepeatChore(mAnimateChore);
  86.     }
  87.     
  88.     //::SetPort(macWindow);
  89.     ::GlobalToLocal(&inEvent.where);
  90. }
  91.  
  92. void
  93. PedPaneIconAnimated::DispatchNullEvent(EventRecord &inEvent)
  94. {
  95.     mSuperView.Focus();
  96.     ::GlobalToLocal(&inEvent.where);
  97.     if (::PtInRect(inEvent.where, &mBounds)) {
  98.         CursHandle cursCross = ::GetCursor(crossCursor);
  99.         ThrowIfNULL_(cursCross);
  100.         ::SetCursor(*cursCross);
  101.     } else
  102.         ::SetCursor(&qd.arrow);
  103. }
  104.